package com.itfetter.api.client.fallback;

import com.itfetter.api.client.ItemClient;
import com.itfetter.api.dto.ItemDTO;
import com.itfetter.api.dto.OrderDetailDTO;
import com.itfetter.common.exception.BizIllegalException;
import com.itfetter.common.utils.CollUtils;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.Collection;
import java.util.List;

public class ItemClientFallback implements FallbackFactory {
    @Override
    public Object create(Throwable cause) {
        return new ItemClient() {
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                return CollUtils.emptyList();
            }

            @Override
            public void deductStock(List<OrderDetailDTO> items) {
                throw new BizIllegalException(cause);
            }

            @Override
            public ItemDTO queryItemById(Long id) {
                throw new BizIllegalException(cause);
            }
        };
    }
}
